package org.hcf.utils.excel.poi.base.exp;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.apache.poi.ss.usermodel.*;
import org.hcf.utils.excel.poi.base.exp.utils.ValidationDataUtils;

import java.util.Collection;
import java.util.Objects;

/**
 * @author changfu.he
 * @date 2021/9/4
 */
@Getter@Setter
@NoArgsConstructor
public class ValidationDataHandler {

    protected Workbook wb;
    protected Sheet sheet;
    protected String validationDataSheetName;
    protected Boolean sheetHiden;
    protected Collection<String> validationDatas;
    protected int firstRow = 1;
    protected int endRow = SimpleExcelHelper.DEFAULT_ROWS -1;
    protected int firstCol;
    protected int endCol;

    public ValidationDataHandler(SimpleExcelHelper excelHelper,
                                 String validationDataSheetName,
                                 Boolean sheetHiden,
                                 Collection<String> validationDatas,
                                 Integer firstCol) {
        this(excelHelper.getWorkbook(), excelHelper.getSheet(), validationDataSheetName, sheetHiden, validationDatas, null,null, firstCol, null);
    }

    public ValidationDataHandler(
                    Workbook wb,
                    Sheet sheet,
                    String validationDataSheetName,
                    Boolean sheetHiden,
                    Collection<String> validationDatas,
                    Integer firstRow,
                    Integer endRow,
                    Integer firstCol,
                    Integer endCol){
        this.wb =wb ;
        this.sheet =sheet ;
        this.validationDataSheetName =validationDataSheetName ;
        this.sheetHiden =sheetHiden ;
        this.validationDatas =validationDatas ;
        this.firstCol =firstCol ;
        if(Objects.nonNull(endCol)) {
            this.endCol = endCol;
        }else{
            this.endCol = firstCol;
        }
        if(Objects.nonNull(firstRow)) {
            this.firstRow = firstRow;
        }
        if(Objects.nonNull(endRow)) {
            this.endRow = endRow;
        }
    }

    public void setDataValidation(){
        ValidationDataUtils.setDataValidation(wb,
                sheet,
                validationDataSheetName,
                sheetHiden,
                validationDatas,
                firstRow,
                endRow,
                firstCol,
                endCol);
    }

}
